const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const args = require('minimist')(process.argv.slice(2));

function resolve (dir) {
    return path.join(__dirname, '..', dir)
}

const config =  {
    entry : {},
    output : {},
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader: 'vue-loader',
                options: {
                    loaders: {
                        css: 'vue-style-loader!css-loader',
                        less: 'vue-style-loader!css-loader!less-loader'
                    },
                    postLoaders: {
                        html: 'babel-loader'
                    }
                }
            },
            {
                test: /\.js$/,
                loader: 'babel-loader', 
                include: [resolve('src'), resolve('/node_modules')]
            },
            {
                test: /\.css$/,
                use: [
                  'vue-style-loader',
                  'css-loader'
                ],
            },
            {
                test: /\.less$/,
                use: [
                    'style-loader',
                    'css-loader',
                    {loader : 'less-loader', options: { javascriptEnabled: true }} 
                ]
            },
            { test: /\.(gif|jpg|png|woff|svg|eot|ttf)\??.*$/, loader: 'url-loader?limit=8192'},
            { test: /\.(html|tpl)$/, loader: 'html-loader' }
        ]
    },
    resolve: {
        alias: {
          'vue$': 'vue/dist/vue.js'
        },
        extensions: ['.js', '.vue'],
        modules : [
            path.resolve('./src'),
            path.resolve('./node_modules')
        ]
    },
    plugins: [
        new VueLoaderPlugin(),
        new ExtractTextPlugin("[name].css"),
        new webpack.optimize.AggressiveMergingPlugin({chiminsizereduceldren: 1.5}),
    ],
    performance:{
        hints:false,
        maxEntrypointSize: 512000,
        maxAssetSize: 512000
    },
    optimization: {
        splitChunks: {
            cacheGroups: {
                commons: {
                    name: "vendor",
                    chunks: "initial",
                    minChunks: 2
                }
            }
        }
    }
}
if(args.env=='pc'){
    config.entry = {
        admin : './src/admin/main.js',
        adminAuth : './src/admin/auth.js',
    };
    config.output = {
        filename : '[name].js',
        publicPath:  '/admin/pc/',
        path : path.resolve(__dirname + '/public/admin/pc'),
    };
}else{
    config.entry = {
        touch : './src/touch/main.js',
        touchAuth : './src/touch/auth.js',
    };
    config.output = {
        filename : '[name].js',
        publicPath:  '/touch/',
        path : path.resolve(__dirname + '/public/touch'),
    };
}
module.exports = config;